package vip.youngboy.freejump.db.constrants;

import java.util.Arrays;
import java.util.Iterator;

public enum ColumnType {

    VARCHAR("varchar", "字符串", new String[]{"varchar", "varchar2", "char", "tinyblob", "tinytext"}),
    CLOB("clob", "大文本", new String[]{"text", "clob", "blob", "mediumblob", "mediumtext", "longblob", "longtext"}),
    NUMBER("number", "数字型", new String[]{"tinyint", "number", "smallint", "mediumint", "int", "integer", "bigint", "float", "double", "decimal", "numeric"}),
    DATE("date", "日期型", new String[]{"date", "time", "year", "datetime", "timestamp"});

    private String key;
    private String desc;
    private String[] supports;

    private ColumnType(String key, String desc, String[] supports) {
        this.key = key;
        this.desc = desc;
        this.supports = supports;
    }

    public static ColumnType getByKey(String key) {
        ColumnType[] var1 = values();
        int var2 = var1.length;

        for (int var3 = 0; var3 < var2; ++var3) {
            ColumnType type = var1[var3];
            if (type.getKey().equals(key)) {
                return type;
            }
        }

        throw new RuntimeException(String.format("找不到key为[%s]的字段类型", key));
    }

    public static ColumnType getByDbDataType(String dbDataType) {
        ColumnType[] var1 = values();
        int var2 = var1.length;

        for (int var3 = 0; var3 < var2; ++var3) {
            ColumnType type = var1[var3];
            Iterator var5 = Arrays.asList(type.supports).iterator();

            while (var5.hasNext()) {
                String support = (String) var5.next();
                if (dbDataType.toLowerCase().contains(support.toLowerCase())) {
                    return type;
                }
            }
        }

        throw new RuntimeException(String.format("数据库类型[%s]转换不了系统支持的类型", dbDataType));
    }

    public String getKey() {
        return this.key;
    }

    public String getDesc() {
        return this.desc;
    }

    public String[] getSupports() {
        return this.supports;
    }

    public boolean equalsWithKey(String key) {
        return this.key.equals(key);
    }

}
